 <? 
include_once('inc/functions.php');
require_once('inc/global.php');
require_once('inc/userdata.php');
 $IsAjax = isset($_REQUEST['IsAjax']);
        //print_r($_REQUEST);
        if(isset($_REQUEST['Save']))
        {
                $rs = $_REQUEST;
                $errors = Users::Validate($rs);
                if(!$errors)
                        $errors = Users::Save($rs);
                if(!$errors)
                {
                        if($IsAjax)
                        {
                                include 'index_details.php';
                                die();
                        }
                        else
                                header("Location: index.php?new_id=$rs[id]");
                }
        }
        elseif(isset($_REQUEST['id']))
                $rs = Users::Get($_REQUEST['id']);
        else
                $rs = Users::Blank();
                
?>
<? if($IsAjax){ ?>
        <form method="post" action="edit.php?IsAjax=true<?=isset($_REQUEST['id']) ? "&id=$_REQUEST[id]" : ''?>">
                <input  type="text"
                        name="FirstName" id="FirstName"
                    value="<?=$rs['FirstName']?>"
                    class="<?=isset($errors['FirstName']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['FirstName']?></span>
                <input  type="text"
                        name="LastName" id="LastName"
                    value="<?=$rs['LastName']?>"
                    class="<?=isset($errors['LastName']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['LastName']?></span>
                <input  type="text"
                        name="PictureURL" id="PictureURL"
                    value="<?=$rs['PictureURL']?>"
                    class="<?=isset($errors['PictureURL']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['PictureURL']?></span>
                <input  type="text"
                        name="FBID" id="FBID"
                    value="<?=$rs['FBID']?>"
                    class="<?=isset($errors['FBID']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['FBID']?></span>
                <input  type="number"
                        name="Lookup_id" id="Lookup_id"
                    value="<?=$rs['Lookup_id']?>"
                    class="<?=isset($errors['Lookup_id']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Lookup_id']?></span>
            <input type="hidden" value="true"  name="Save"/>
            <input type="submit" value="Save"/>
            <a href="#" class="cancel">Cancel</a>
       </form>

<? }else{ ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Management</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center" style="margin-top:40px;">
<h1>Edit All User Data</h1>
<div class="monkey">
<pre><? // print_r($_REQUEST);?></pre>
<form method="post" action="" class="form">
        ﻿<label>id:</label>
        ﻿<?=$rs['id']?>
            <br />
        ﻿<label for="created_at">created_at</label>
        ﻿<input ﻿type="datetime"
          name="created_at" id="created_at"
                    value="<?=$rs['created_at']?>"
                    class="<?=isset($errors['created_at']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['created_at']?></span>
            <br />
        ﻿<label for="updated_at">updated_at</label>
        ﻿<input  type="datetime" name="updated_at" id="updated_at"
                    value="<?=$rs['updated_at']?>"
                    class="<?=isset($errors['updated_at']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['updated_at']?></span>
            <br />
        ﻿<label for="User_id">User_id</label>
        ﻿<input  type="number"
            ﻿name="User_id" id="User_id"
                    value="<?=$rs['User_id']?>"
                    class="<?=isset($errors['User_id']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['User_id']?></span>
            <br />
        ﻿<label for="Lookup_id">Lookup_id</label>
        ﻿<input ﻿type="number"
            ﻿name="Lookup_id" id="Lookup_id"
                    value="<?=$rs['Lookup_id']?>"
                    class="<?=isset($errors['Lookup_id']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Lookup_id']?></span>
            <br />
        ﻿<label for="Value">Value</label>
        ﻿<input ﻿type="<?= $rs['Lookup_id']==7 ? 'email' : ($rs['Lookup_id']==8 ? 'tel' : 'text') ?>"
            ﻿name="Value" id="Value"
                    value="<?=$rs['Value']?>"
                    class="<?=isset($errors['Value']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Value']?></span>
            <br />
            <input type="submit" value="Save" />
        </form>
</div>
<a style="color: #FFF;" href = "javascript:history.back()">Back</a>
</div>
</body>
</html>